package com.heima.test7;

import java.io.*;
import java.net.Socket;

public class UploadClient {
    public static void main(String[] args) throws IOException {
        //1.创建客户端对象 传入服务器Ip和端口号 连接服务器
        Socket socket = new Socket("192.168.16.96", 1000);

        //创建客户端输出流发送数据
        OutputStream os = socket.getOutputStream();


        //2.读取文件发送给服务器
        FileInputStream fis = new FileInputStream("123.jpg");
        int len;
        byte[] bytes = new byte[1024];
        while ((len = fis.read()) != -1) {
            os.write(bytes, 0, len);
        }
        //5结束输出流 让对方得到结束标记
        socket.shutdownOutput();

        //获取网络输入流 用来得到服务器的回复数据
        InputStream is = socket.getInputStream();
        byte[] bytesReceive = new byte[1024];
        int len1 = is.read(bytesReceive);
        System.out.println(new String(bytesReceive, 0, len1));

        fis.close();
        os.close();
        socket.close();


    }
}
